<template>
  <a-card>
    <!-- 查询条件 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline">
        <a-collapse v-model="collapseKey" class="collapseArea" expandIconPosition="right">
          <a-collapse-panel key="1" style="font-weight: bold">
            <div slot="header" class="collapseArea_header">
              <a-row :gutter="48">
                <a-col @click.stop="() => {}" :md="6" :sm="24">
                  <a-form-item label="法律名称：">
                    <a-input v-model="queryParam.f_title" placeholder="请输入法律名称" allowClear />
                  </a-form-item>
                </a-col>
                <a-col @click.stop="() => {}" :md="6" :sm="24">
                  <a-form-item label="法律性质：">
                    <a-select
                      v-model="queryParam.f_type"
                      placeholder="请选择法律性质"
                      style="font-weight: normal"
                      allowClear
                      showSearch
                      :filter-option="filterOption"
                    >
                      <a-select-option v-for="item in lawTypeList" :key="item.value" :value="item.value">
                        {{ item.name }}
                      </a-select-option>
                    </a-select>
                  </a-form-item>
                </a-col>

                <a-col @click.stop="() => {}" :md="6" :sm="24">
                  <a-form-item label="发布机关：">
                    <a-select
                      v-model="queryParam.f_pubunitid"
                      placeholder="请选择发布机关"
                      style="font-weight: normal"
                      allowClear
                      showSearch
                      :filter-option="filterOption"
                    >
                      <a-select-option v-for="item in unitList" :key="item.id" :value="item.id">
                        {{ item.name }}
                      </a-select-option>
                    </a-select>
                  </a-form-item>
                </a-col>

                <a-col :md="6" :sm="24">
                  <a-button
                    type="primary"
                    class="btn_primary_color"
                    style="margin-left: 20px"
                    @click.stop="queryList(queryParam)"
                    icon="search"
                    >查询
                  </a-button>
                  <a-button icon="reload" class="btn_normal_color" style="margin-left: 8px" @click.stop="reQuery"
                    >重置
                  </a-button>
                </a-col>
              </a-row>
            </div>
            <a-row :gutter="48" class="collapseArea_body">
              <a-col @click.stop="() => {}" :md="6" :sm="24">
                <a-form-item label="发布日期：">
                  <a-date-picker
                    v-model="queryParam.f_pubStartDate"
                    :style="{ width: 'calc(50% - 12px)' }"
                    placeholder="开始日期"
                    format="YYYY-MM-DD"
                    allowClear
                    @change="pubDateListen()"
                  />
                  ~
                  <a-date-picker
                    v-model="queryParam.f_pubEndDate"
                    :style="{ width: 'calc(50% - 12px)' }"
                    placeholder="结束日期"
                    format="YYYY-MM-DD"
                    allowClear
                    @change="pubDateListen()"
                  />
                </a-form-item>
              </a-col>

              <a-col @click.stop="() => {}" :md="6" :sm="24">
                <a-form-item label="施行日期：">
                  <a-date-picker
                    v-model="queryParam.f_execStartDate"
                    :style="{ width: 'calc(50% - 12px)' }"
                    placeholder="开始日期"
                    format="YYYY-MM-DD"
                    allowClear
                    @change="execDateListen()"
                  />
                  ~
                  <a-date-picker
                    v-model="queryParam.f_execEndDate"
                    :style="{ width: 'calc(50% - 12px)' }"
                    placeholder="结束日期"
                    format="YYYY-MM-DD"
                    allowClear
                    @change="execDateListen()"
                  />
                </a-form-item>
              </a-col>

              <a-col @click.stop="() => {}" :md="6" :sm="24">
                <a-form-item label="有效性：">
                  <a-select
                    v-model="queryParam.f_status"
                    placeholder="请选择有效性"
                    style="font-weight: normal"
                    allowClear
                    showSearch
                    :filter-option="filterOption"
                  >
                    <a-select-option v-for="item in lawValidTypeList" :key="item.value" :value="item.value">
                      {{ item.name }}
                    </a-select-option>
                  </a-select>
                </a-form-item>
              </a-col>

              <a-col @click.stop="() => {}" :md="6" :sm="24">
                <a-form-item label="来源途径：">
                  <a-select
                    v-model="queryParam.f_source"
                    placeholder="请选择来源途径"
                    style="font-weight: normal"
                    allowClear
                    showSearch
                    :filter-option="filterOption"
                  >
                    <a-select-option v-for="item in lawSrcTypeList" :key="item.value" :value="item.value">
                      {{ item.name }}
                    </a-select-option>
                  </a-select>
                </a-form-item>
              </a-col>

              <a-col @click.stop="() => {}" :md="6" :sm="24">
                <a-form-item label="发布文号：">
                  <a-input v-model="queryParam.f_pubcode" placeholder="请输入发布文号" allowClear />
                </a-form-item>
              </a-col>

              <a-col @click.stop="() => {}" :md="6" :sm="24">
                <a-form-item label="失效日期">
                  <a-date-picker
                    v-model="queryParam.f_loseStartDate"
                    :style="{ width: 'calc(50% - 12px)' }"
                    placeholder="开始日期"
                    format="YYYY-MM-DD"
                    allowClear
                    @change="loseDateListen()"
                  />
                  ~
                  <a-date-picker
                    v-model="queryParam.f_loseEndDate"
                    :style="{ width: 'calc(50% - 12px)' }"
                    placeholder="结束日期"
                    format="YYYY-MM-DD"
                    allowClear
                    @change="loseDateListen()"
                  />
                </a-form-item>
              </a-col>

              <a-col @click.stop="() => {}" :md="6" :sm="24">
                <a-form-item label="收录日期">
                  <a-date-picker
                    v-model="queryParam.f_recordStartDate"
                    :style="{ width: 'calc(50% - 12px)' }"
                    placeholder="开始日期"
                    format="YYYY-MM-DD"
                    allowClear
                    @change="recordDateListen()"
                  />
                  ~
                  <a-date-picker
                    v-model="queryParam.f_recordEndDate"
                    :style="{ width: 'calc(50% - 12px)' }"
                    placeholder="结束日期"
                    format="YYYY-MM-DD"
                    allowClear
                    @change="recordDateListen()"
                  />
                </a-form-item>
              </a-col>
            </a-row>
          </a-collapse-panel>
        </a-collapse>
        <div style="display: flex">
          <div class="headerdefBox">
            <a-tooltip placement="topLeft">
              <template slot="title">
                <span>重置表格</span>
              </template>
              <img
                @click="resetting()"
                style="margin-right: 16px; margin-top: 30%"
                src="@/assets/icons/table/table_refresh.png"
                alt="重置"
              />
            </a-tooltip>

            <a-tooltip placement="topLeft">
              <template slot="title">
                <span>设置表格</span>
              </template>
              <img
                @click="showHeaderDef($event)"
                style="margin-top: 30%"
                src="@/assets/icons/table/table_config.png"
                alt="表格设置"
              />
            </a-tooltip>
          </div>
          <!-- 导出按钮 -->
          <div style="margin-bottom: 16px; margin-bottom: 10px; margin-left: 78%">
            <a-button type="primary" class="m-l-8 btn_primary_color" @click="addHandleData" icon="plus"
              >新增法律条文
            </a-button>
          </div>
        </div>
      </a-form>
    </div>

    <!-- 自定义表头组件 -->
    <HEADERDEFINITION ref="headerDefRef" :ucolumns="ucolumns" @f_setColumns="s_setColumns" />

    <!-- 表格数据 -->
    <a-table
      :scroll="{ x: 1000, y: 440 }"
      :columns="ucolumns"
      :data-source="listData"
      :pagination="upagination"
      :loading="loading"
      rowKey="id"
      @change="tableChange"
      size="middle"
      :bordered="ubordered"
      :rowClassName="rowClassName"
    >
      <span slot="serial" slot-scope="text, record, index">
        {{ (upagination.current - 1) * upagination.pageSize + parseInt(index) + 1 }}
      </span>

      <div slot="typeSlot" slot-scope="type" class="overBox" style="width: 100%">
        <a-tooltip placement="topLeft">
          <template slot="title">
            <span>{{ typeLable(type) }}</span>
          </template>
          {{ typeLable(type) }}
        </a-tooltip>
      </div>

      <div slot="statusSlot" slot-scope="status" class="overBox" style="width: 100%">
        <a-tooltip placement="topLeft">
          <template slot="title">
            <span>{{ statusLable(status) }}</span>
          </template>
          {{ statusLable(status) }}
        </a-tooltip>
      </div>

      <div slot="sourceSlot" slot-scope="source" class="overBox" style="width: 100%">
        <a-tooltip placement="topLeft">
          <template slot="title">
            <span>{{ sourceLable(source) }}</span>
          </template>
          {{ sourceLable(source) }}
        </a-tooltip>
      </div>

      <div slot="titleSlot" slot-scope="title" class="overBox" style="width: 100%; text-align: left">
        <a-tooltip placement="topLeft">
          <template slot="title">
            <span>{{ title }}</span>
          </template>
          {{ title }}
        </a-tooltip>
      </div>

      <div slot="pubcodeSlot" slot-scope="pubcode" class="overBox" style="width: 100%">
        <a-tooltip placement="topLeft">
          <template slot="title">
            <span>{{ pubcode }}</span>
          </template>
          {{ pubcode }}
        </a-tooltip>
      </div>

      <span slot="operation" slot-scope="text, record">
        <template>
          <a @click="lawDetail(record)">详情</a>
          <a-divider type="vertical" />
          <a @click="editHandleData(record)">编辑</a>
          <a-divider type="vertical" />
          <a @click="uploadFile(record)">上传附件</a>
          <a-divider type="vertical" v-if="hasFile(record)" />
          <a @click="downloadFile(record)" v-if="hasFile(record)">下载附件</a>

          <a-divider type="vertical" v-if="record.versions != 1" />
          <a @click="drawer(record)" v-if="record.versions != 1">历史版本</a>

          <!-- 抽屉组件 -->
          <a-drawer
            placement="right"
            :visible="ishashistory"
            @close="closeDrawer"
            :closable="false"
            title="历史版本"
            width="720"
          >
            <template>
              <a-list class="demo-loadmore-list" :loading="loading" item-layout="horizontal" :data-source="historyData">
                <div
                  slot="loadMore"
                  :style="{ textAlign: 'center', marginTop: '12px', height: '32px', lineHeight: '32px' }"
                ></div>
                <a-list-item slot="renderItem" slot-scope="item, index">
                  <a slot="actions" @click="lawDetail(item)">详情</a>
                  <a slot="actions" @click="editHandleData(item)">编辑</a>
                  <a slot="actions" @click="uploadFile(item)">上传附件</a>
                  <a slot="actions" @click="downloadFile(item)" v-if="hasFile(item)">下载附件</a>

                  <a-list-item-meta>
                    <a slot="title" href="https://www.antdv.com/">{{ item.title }}</a>
                  </a-list-item-meta>
                  <div>{{ item.pubunitname }}</div>
                </a-list-item>
              </a-list>
            </template>
          </a-drawer>
        </template>
      </span>
    </a-table>

    <!-- 导入数据弹窗 -->
    <a-modal
      title="上传法律法规文件"
      v-model="importVisible"
      destroyOnClose
      @cancel="importCancel"
      @ok="handleImportOk"
      :maskClosable="false"
    >
      <a-alert type="info" show-icon>
        <span slot="message"> 请按照对应格式上传法律法规文件 </span>
      </a-alert>
      <br />
      <a-upload-dragger
        name="file"
        accept=".doc,.docx"
        @reject="handleImportReject"
        :before-upload="beforeImportUpload"
        :show-upload-list="false"
      >
        <div v-if="importFile.name">
          <a-row class="l-h-25">
            <a-col :span="8" class="p-r-10">
              <p class="ant-upload-drag-icon m-b-0">
                <a-icon type="file" />
              </p>
            </a-col>
            <a-col :span="16" class="text-left">
              <p class="ant-upload-hint">
                {{ importFile.name }}
              </p>
              <p class="ant-upload-hint">将文件拖到此处或点击此处重新上传</p>
            </a-col>
          </a-row>
        </div>
        <div v-else>
          <p class="ant-upload-drag-icon m-b-0">
            <a-icon type="cloud-upload" />
          </p>
          <p class="ant-upload-hint">您可以将文件拖到此处或点击此处上传</p>
          <p class="ant-upload-hint">文件格式为doc,docx,pdf</p>
        </div>
      </a-upload-dragger>
      <br />
    </a-modal>

    <a-drawer
      :title="isEdit ? '编辑法律法规' : '添加法律法规'"
      width="38%"
      :visible="visible_edit"
      :body-style="{ paddingBottom: '80px' }"
      @close="visible_edit = false"
      destroyOnClose
    >
      <LawInfoAdd
        ref="edit"
        @close="visible_edit = false"
        @reloadList="queryList"
        :unitList="unitList"
        :infoForm="infoForm"
      ></LawInfoAdd>
    </a-drawer>
  </a-card>
</template>
<script>
import { getAllPubunitList } from '@/api/law/law_pubunit'
import { getLawDocPage, uploadLawFile } from '@/api/law/law_doc'
import { Tp_lawList } from '@/enumeration/Tp_law'
import { Tp_lawsrcList } from '@/enumeration/Tp_lawsrc'
import { St_lawList } from '@/enumeration/St_law'
import { Tp_provision } from '@/enumeration/Tp_provision'
import { getUrl } from '@/api/base/file.js'
import storage from 'store'
import { APP_USER } from '@/store/mutation-types.js'
import { FILETYPE, FILESIZE } from '@/store/mutation-types'
import { getHistoryVersion } from '@/api/law/law_provision'

export default {
  data () {
    return {
      collapseKey: [1], // 折叠面板key
      ucolumns: [
        {
          title: '序号',
          width: 50,
          key: 'index',
          align: 'center',
          fixed: 'left',
          scopedSlots: { customRender: 'serial' }
        },
        {
          title: '名称',
          dataIndex: 'title',
          key: 'title',
          width: 270,
          sorter: (a, b) => String(a.title).localeCompare(String(b.title)),
          align: 'center',
          scopedSlots: { customRender: 'titleSlot' }
        },
        {
          title: '法律性质',
          dataIndex: 'type',
          key: 'type',
          width: 100,
          sorter: (a, b) => String(a.type).localeCompare(String(b.type)),
          align: 'center',
          scopedSlots: { customRender: 'typeSlot' }
        },
        {
          title: '发布机关',
          dataIndex: 'pubunitname',
          key: 'pubunitname',
          width: 150,
          sorter: (a, b) => String(a.pubunitname).localeCompare(String(b.pubunitname)),
          align: 'center'
        },
        {
          title: '发布日期',
          dataIndex: 'pubdate',
          key: 'pubdate',
          width: 150,
          sorter: (a, b) => String(a.pubdate).localeCompare(String(b.pubdate)),
          align: 'center'
        },
        {
          title: '施行日期',
          dataIndex: 'execdate',
          key: 'execdate',
          width: 150,
          sorter: (a, b) => String(a.execdate).localeCompare(String(b.execdate)),
          align: 'center'
        },
        {
          title: '有效性',
          dataIndex: 'status',
          key: 'status',
          width: 150,
          sorter: (a, b) => String(a.status).localeCompare(String(b.status)),
          align: 'center',
          scopedSlots: { customRender: 'statusSlot' }
        },
        {
          title: '失效日期',
          width: 150,
          key: 'losedate',
          dataIndex: 'losedate',
          sorter: (a, b) => String(a.losedate).localeCompare(String(b.losedate)),
          align: 'center'
        },
        {
          title: '收录日期',
          width: 150,
          key: 'recorddate',
          dataIndex: 'recorddate',
          sorter: (a, b) => String(a.recorddate).localeCompare(String(b.recorddate)),
          align: 'center'
        },
        {
          title: '来源途径',
          width: 150,
          key: 'source',
          dataIndex: 'source',
          sorter: (a, b) => String(a.source).localeCompare(String(b.source)),
          align: 'center',
          scopedSlots: { customRender: 'sourceSlot' }
        },
        {
          title: '发布文号',
          width: 350,
          key: 'pubcode',
          dataIndex: 'pubcode',
          sorter: (a, b) => String(a.pubcode).localeCompare(String(b.pubcode)),
          align: 'center',
          scopedSlots: { customRender: 'pubcodeSlot' }
        },
        {
          title: '操作',
          dataIndex: 'action',
          key: 'action',
          width: 300,
          fixed: 'right',
          align: 'center',
          scopedSlots: { customRender: 'operation' }
        }
      ],
      queryParam: {
        f_title: '', //法律名称
        f_type: undefined, // 法律性质
        f_pubunitid: undefined, // 法律发布机关
        f_source: undefined, //来源途径
        f_pubcode: '', //发布文号
        f_status: undefined, //有效性
        f_pubStartDate: null, // 发布开始日期
        f_pubEndDate: null, //
        f_execStartDate: null, // 施行开始日期
        f_execEndDate: null, //
        f_loseStartDate: null, // 失效开始日期
        f_loseEndDate: null,
        f_recordStartDate: null, // 收录开始日期
        f_recordEndDate: null,
        f_versions: '', //版本号
        f_groups: '', //法律文书分类
        pageNumber: 1,
        pageSize: 20,
        sort: 'pubdate',
        order: 'desc'
      },
      listData: [],
      ishashistory: false, //历史版本弹窗判断
      historyData: [], //历史版本信息
      upagination: {
        // 表格分页参数
        defaultPageSize: 20,
        total: 0,
        current: 1,
        pageSize: 20,
        showTotal: total => `共${total}条数据`,
        showSizeChanger: true,
        pageSizeOptions: ['10', '20', '50', '100']
      },
      loading: false,
      ubordered: true, // 表格边框是否显示
      currentUser: storage.get(APP_USER), // 登录人信息
      unitList: [], // 发布机关查询数据
      Tp_lawList: Tp_lawList, // 法律性质
      lawTypeList: [], // 法律性质下拉框数据
      Tp_lawsrcList: Tp_lawsrcList, // 来源途径
      lawSrcTypeList: [], //来管途径下拉框数据
      St_lawList: St_lawList, // 法律有效性
      lawValidTypeList: [], //法律有效性下拉框数据
      Tp_provision: Tp_provision, //法律条文类别
      importVisible: false, // 导入文件模态框
      importFile: {}, // 上传文件
      selectLawData: {}, //上传文件选择的法律文件
      visible_edit: false,
      isEdit: false,
      infoForm: {
        id: '',
        title: '',
        type: undefined,
        pubunitid: undefined,
        pubdate: undefined,
        execdate: undefined,
        status: undefined,
        losedate: undefined,
        recorddate: undefined,
        source: undefined,
        pubcode: '',
        isAdd: true
      }
    }
  },
  components: {
    HEADERDEFINITION: () => import('@/views/customComponents/headerDefinition.vue'),
    LawInfoAdd: () => import('@/views/lawInfo/law/LawInfoAdd.vue')
  },
  computed: {},
  created () {
    let routeParam
    try {
      //console.log('this.$route.query.queryParam.created', this.$route.query.queryParam.TempqueryParam)
      routeParam = JSON.parse(JSON.stringify(this.$route.query.queryParam.TempqueryParam))
      this.queryParam = { ...this.queryParam, ...this.$route.query.queryParam.TempqueryParam }
    } catch {
      console.log('路由传参非json格式')
    }



    this.lawTypeList = Tp_lawList
    this.lawSrcTypeList = Tp_lawsrcList
    this.lawValidTypeList = St_lawList
    this.queryUnitList() //查询发布机关数据
    this.queryList()
  },
  updated () {},
  methods: {
    // 重置表头方法
    resetting () {
      this.$refs.headerDefRef.f_resetting()
    },
    // 子组件回调函数, 重置表头
    s_setColumns (columns) {
      this.ucolumns = columns
    },
    // 显示自定义表头组件
    showHeaderDef (e) {
      this.$refs.headerDefRef.f_init(e)
    },

    filterOption (input, option) {
      return option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
    },

    // 新增页面
    addHandleData () {
      this.isEdit = false
      this.visible_edit = true
      this.infoForm = {
        id: '',
        title: '',
        type: undefined,
        pubunitid: undefined,
        pubdate: undefined,
        execdate: undefined,
        status: undefined,
        losedate: undefined,
        recorddate: undefined,
        source: undefined,
        pubcode: '',
        isAdd: true
      }
      this.$nextTick(() => {
        this.$refs.edit.resetForm()
      })
    },
    // 编辑数据
    editHandleData (record) {
      this.isEdit = true
      this.visible_edit = true
      this.infoForm.id = record.id
      this.infoForm.title = record.title
      this.infoForm.type = record.type
      this.infoForm.pubunitid = record.pubunitid
      this.infoForm.pubdate = record.pubdate
      this.infoForm.execdate = record.execdate
      this.infoForm.status = record.status
      this.infoForm.losedate = record.losedate
      this.infoForm.recorddate = record.recorddate
      this.infoForm.source = record.source
      this.infoForm.pubcode = record.pubcode
      this.infoForm.isAdd = false
    },
    /**
     * 重置查询条件并查询数据
     */
    reQuery () {
      ;(this.queryParam = {
        f_title: '', //法律名称
        f_type: undefined, // 法律性质
        f_pubunitid: undefined, // 法律发布机关
        f_source: undefined, //来源途径
        f_pubcode: '', //发布文号
        f_status: undefined, //有效性
        f_pubStartDate: null, // 发布开始日期
        f_pubEndDate: null, //
        f_execStartDate: null, // 施行开始日期
        f_execEndDate: null, //
        f_loseStartDate: null, // 失效开始日期
        f_loseEndDate: null,
        f_recordStartDate: null, // 收录开始日期
        f_recordEndDate: null,
        pageNumber: 1,
        pageSize: 20,
        sort: 'pubdate',
        order: 'desc'
      }),
        this.queryList()
    },
    // 查询全部的发布机关
    async queryUnitList () {
      await getAllPubunitList().then(res => {
        // console.log('查询参数', params)
        if (res.code == 0 && res.data) {
          this.unitList = res.data
        } else {
          this.unitList = []
        }
      })
    },

    tableChange (upagination, filters, sorter, { currentDataSource }) {
      this.row_idx = upagination.current * upagination.pageSize - upagination.pageSize
      this.queryParam.pageNumber = upagination.current
      this.queryParam.pageSize = upagination.pageSize
      this.queryList()
    },
    // 接收时间监听判断开始结束日期是否合理
    pubDateListen () {
      if (
        this.queryParam.f_pubStartDate > this.queryParam.f_pubEndDate &&
        this.queryParam.f_pubStartDate &&
        this.queryParam.f_pubEndDate
      ) {
        this.queryParam.f_pubStartDate = undefined
      }
    },
    execDateListen () {
      if (
        this.queryParam.f_execStartDate > this.queryParam.f_execEndDate &&
        this.queryParam.f_execStartDate &&
        this.queryParam.f_execEndDate
      ) {
        this.queryParam.f_execStartDate = undefined
      }
    },
    loseDateListen () {
      if (
        this.queryParam.f_loseStartDate > this.queryParam.f_loseEndDate &&
        this.queryParam.f_loseStartDate &&
        this.queryParam.f_loseEndDate
      ) {
        this.queryParam.f_loseStartDate = undefined
      }
    },
    recordDateListen () {
      if (
        this.queryParam.f_recordStartDate > this.queryParam.f_recordEndDate &&
        this.queryParam.f_recordStartDate &&
        this.queryParam.f_recordEndDate
      ) {
        this.queryParam.f_recordStartDate = undefined
      }
    },

    /**
     * 法律性质显示转换
     */
    typeLable (val) {
      for (let key in this.Tp_lawList) {
        if (this.Tp_lawList[key].value == val) {
          return this.Tp_lawList[key].name
        }
      }
      return val
    },
    /**
     * 有效性显示转换
     */
    statusLable (val) {
      for (let key in this.St_lawList) {
        if (this.St_lawList[key].value == val) {
          return this.St_lawList[key].name
        }
      }
      return val
    },
    /**
     * 来源途径显示转换
     */
    sourceLable (val) {
      for (let key in this.Tp_lawsrcList) {
        if (this.Tp_lawsrcList[key].value == val) {
          return this.Tp_lawsrcList[key].name
        }
      }
      return val
    },
    drawer (record) {
      this.ishashistory = !this.ishashistory
      this.getHistoryData(record)
    },
    closeDrawer () {
      this.ishashistory = false
    },

    /**
     * 获取历史版本法律条文的具体细项数据
     */
    getHistoryData (record) {
      let cpQueryParam = JSON.parse(JSON.stringify(this.queryParam))
      if (this.queryParam.f_title) {
        cpQueryParam.f_title = null
      }

      cpQueryParam.f_groups = record.groups

      console.log('cpqueryparam', cpQueryParam)

      this.loading = true
      getHistoryVersion(cpQueryParam)
        .then(res => {
          console.log('res  ', res)
          if (res.code !== 0) {
            this.$message.error('获取数据失败')
          } else {
            // debugger
            this.historyData = res.data.records
            // 默认展开全部的
            this.activeKey = []
            for (let index in this.historyData) {
              this.activeKey.push(String(index))
            }
          }
        })
        .catch(err => {
          this.historyData = []
          console.log(err, '获取数据失败')
        })
        .finally(() => {
          this.loading = false
        })
    },

    queryList () {
      // 时间转换
      let cpQueryParam = JSON.parse(JSON.stringify(this.queryParam))
      if (this.queryParam.pubStartDate?.format) {
        cpQueryParam.pubStartDate = this.queryParam.pubStartDate.format('YYYY-MM-DD') + ' 00:00:00'
      }
      if (this.queryParam.pubEndDate?.format) {
        cpQueryParam.pubEndDate = this.queryParam.pubEndDate.format('YYYY-MM-DD') + ' 23:59:59'
      }
      if (this.queryParam.execStartDate?.format) {
        cpQueryParam.execStartDate = this.queryParam.execStartDate.format('YYYY-MM-DD') + ' 00:00:00'
      }
      if (this.queryParam.execEndDate?.format) {
        cpQueryParam.execEndDate = this.queryParam.execEndDate.format('YYYY-MM-DD') + ' 23:59:59'
      }
      if (this.queryParam.loseStartDate?.format) {
        cpQueryParam.loseStartDate = this.queryParam.loseStartDate.format('YYYY-MM-DD') + ' 00:00:00'
      }
      if (this.queryParam.loseEndDate?.format) {
        cpQueryParam.loseEndDate = this.queryParam.loseEndDate.format('YYYY-MM-DD') + ' 23:59:59'
      }
      if (this.queryParam.recordStartDate?.format) {
        cpQueryParam.recordStartDate = this.queryParam.recordStartDate.format('YYYY-MM-DD') + ' 00:00:00'
      }
      if (this.queryParam.recordEndDate?.format) {
        cpQueryParam.recordEndDate = this.queryParam.recordEndDate.format('YYYY-MM-DD') + ' 23:59:59'
      }
      if (this.queryParam.f_title) {
        cpQueryParam.f_title = this.queryParam.f_title.toString().trim()
      }
      if (this.queryParam.f_pubcode) {
        cpQueryParam.f_pubcode = this.queryParam.f_pubcode.toString().trim()
      }
      this.loading = true
      getLawDocPage(cpQueryParam)
        .then(res => {
          if (res.code !== 0) {
            this.$message.error('获取数据失败')
          } else {
            this.listData = res.data.records
            this.upagination.total = res.data.total
            this.upagination.current = res.data.current
            this.upagination.pageSize = res.data.size
          }
        })
        .catch(err => {
          this.listData = []
          console.log(err, '获取数据失败')
        })
        .finally(() => {
          this.loading = false
        })
    },
    // 判断是否上传了文件
    hasFile (record) {
      if (record.fileid != null && record.fileid != '' && record.fileid != undefined) {
        return true
      } else {
        return false
      }
    },
    uploadFile (record) {
      this.selectLawData = record
      this.importVisible = true
    },
    // 导入文件
    handleImportOk () {
      // 调用上传接口获取保存的fileId,
      if (!this.importFile) {
        this.$message.warning('请添加上传文件')
        return
      }
      let _this = this
      this.confirmLoading = true
      uploadLawFile({ id: _this.selectLawData.id }, _this.importFile).then(res => {
        if (res.code == 0) {
          _this.importVisible = false
          _this.confirmLoading = false
          _this.$message.success('上传成功')
          _this.queryList()
          _this.importFile = {}
        } else {
          _this.$message.error('上传失败')
        }
      })
    },
    importCancel () {
      this.selectLawData = undefined
      this.importFile = {}
    },
    /**
     * 拖拽验证文件类型
     */
    handleImportReject (file) {
      this.beforeImportUpload(file)
    },
    /**
     * 上传导入文件前验证文件类型
     */
    beforeImportUpload (file) {
      return new Promise((resolve, reject) => {
        //文件格式是否为doc、docx
        let isAcceptType = file.name.toLowerCase().substr(file.name.lastIndexOf('.'))
        let acceptType = 'doc、docx、pdf'
        if (!(isAcceptType == '.doc' || isAcceptType == '.docx' || isAcceptType == '.pdf')) {
          this.$message.warning('请上传' + acceptType + '格式文件')
          return reject(false)
        }
        //文件小于20M
        let isLtSize = file.size / 1024 / 1024 < FILESIZE
        if (!isLtSize) {
          this.$message.warning('请上传' + FILESIZE + 'MB以内的文件')
          return reject(false)
        }
        this.importFile = file
        return resolve(false)
      })
    },
    // 下载文件
    downloadFile (record) {
      getUrl({ id: record.fileid }).then(res => {
        if (res.code == 0) {
          window.open(res.data)
        } else {
          this.$message.error('获取文件下载地址失败')
        }
      })
    },
    // 查询详情
    lawDetail (record) {
      // 格式化对应的显示数据
      let newRecord = JSON.parse(JSON.stringify(record))
      newRecord.type_text = this.typeLable(newRecord.type) // 法律性质
      newRecord.status_text = this.statusLable(newRecord.status) // 有效性
      newRecord.source_text = this.sourceLable(newRecord.source) // 来源途径
      newRecord.TempqueryParam = this.queryParam
      this.$router.push({
        path: '/LawInfoDetail',
        query: {
          url: '/LawInfo',
          params: newRecord
        }
      })
      //console.log('this.queryParam',this.queryParam);
    },
    rowClassName (record, index) {
      return index % 2 === 0 ? 'oddRow' : 'evenRow'
    }
  }
}
</script>

<style lang="less" scoped>
@import '~@/components/TableDrag/style.less';

.demo-loadmore-list {
  min-height: 350px;
}
::v-deep .ant-table-thead > tr > th {
  font-weight: 600;
}

.label-div {
  padding: 10px;
  height: 100%;
  display: inline-block;
  width: 100%;
}

.label-title {
  float: left;
  font-size: 16px;
  font-weight: bold;
}

.add-btn {
  float: right;
  margin-right: 20px;
}

.input-single {
  width: 200px;
}

.headerdefBox img {
  height: 20px;
  width: 20px;
}

.headerdefBox {
  // border: 1px solid red;
  margin: 0 10px 10px 0;
  display: flex;
}

.formArea {
  margin-bottom: 30px;
}

.collapseArea {
  border: none;

  .ant-collapse-item {
    border-bottom: none;
  }

  /deep/ .ant-collapse-content {
    border-top: none;
  }
}

/deep/ .ant-collapse-header {
  background-color: #fff;
}

.collapseArea_header {
  .ant-form-item {
    margin-bottom: 0;
  }
}

.collapseArea_body {
  padding-top: 10px;
  padding: 0 20px 0 0px;
}

.overBox {
  width: 90%;
  overflow: hidden; /*超出部分隐藏*/
  white-space: nowrap; /*不换行*/
  text-overflow: ellipsis; /*超出部分文字以...显示*/
}
</style>
